package com.jml.简单队列点对点;

import com.jml.rabbitmq.RabbitMQConnection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 点对点模式，不用绑定交换机
 */
public class Producer {
    private static final String QUEUE_NAME = "jml-queue";

    public static void main(String[] args) throws IOException, TimeoutException {
        //1.创建一个新连接
        Connection connection = RabbitMQConnection.getConnection();
        //2.设置channel
        Channel channel = connection.createChannel();
        //创建队列,如果没有队列就创建,存在就不创建  第二个参数是队列持久化
        //如果服务器上的队列信息属性和这些属性不符会报错
        channel.queueDeclare(QUEUE_NAME, true, false, false, null);
        //3.发送消息
        String msg = "jml6666";
        channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());
        System.out.println("消息投递成功");
        channel.close();
        connection.close();
    }
}
